package model;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class Booking {
	private String first;
	private String last;
	private Event event;
	
	public Booking(String first, String last, Event event){
		
		this.first = first;
		this.last = last;
		this.event = event;
	}
	
	public String toFile(){
		return first + " " + last + " " + event;
	}
	public void save(){
		try {
			  // Create file 
			  FileWriter fstream = new FileWriter("src\\data\\bookings\\"+event.getID(),true);//add true to append
			  BufferedWriter out1 = new BufferedWriter(fstream);
			  out1.write("\n"+toFile());
			  //Close the output stream
			  out1.close();
		} 
		catch (IOException e) {
			System.out.println("Unexpected error");
			//e.printStackTrace();
		}
	}
	
	public static void viewbookings(int id){
		
		try {
			FileReader in = new FileReader("src\\data\\bookings\\"+id);
			Scanner src = new Scanner(in);
			while(src.hasNextLine()){
				String line = src.nextLine();
				System.out.println(line);
			}
			
		} catch (FileNotFoundException e) {
			System.out.println("No Booking exist for this event");
			//e.printStackTrace();
		}
	}
}
